package laba8;

import interfaces.task8.CyclicItem;
import java.io.Serializable;
import java.util.Objects;

/**
 * Implementation of the CyclicItem
 * @author yakimovich
 */
public class CyclicItemImpl
        implements CyclicItem, Serializable {

    private Object value;
    private transient Object temp;
    private CyclicItem nextItem;

    /**
     * Creates a CyclicItemImpl by default.
     */
    public CyclicItemImpl() {
        nextItem = this;
    }

    /**
     * Creates a CyclicItemImpl with by the specified fields
     * @param value
     * @param temp
     */
    public CyclicItemImpl(Object value, Object temp) {
        this();
        this.value = value;
        this.temp = temp;
    }

    /**
     * Set the value.
     * @param o value
     */
    @Override
    public void setValue(Object o) {
        this.value = o;
    }

    /**
     * @return value.
     */
    @Override
    public Object getValue() {
        return value;
    }

    /**
     * Set the temp.
     * @param o the temp
     */
    @Override
    public void setTemp(Object o) {
        this.temp = o;
    }

    /**
     * @return temp.
     */
    @Override
    public Object getTemp() {
        return temp;
    }

    /**
     * @return nextItem.
     */
    @Override
    public CyclicItem nextItem() {
        return nextItem;
    }

    /**
     * Set nextItem.
     * @param ci nextItem
     */
    @Override
    public void setNextItem(CyclicItem ci) {
        this.nextItem = ci;
    }

    /**
     * The method show displays information about the fields of the class.
     */
    public void showDetails() {
        System.out.println("Value    : " + value);
        System.out.println("Temp     : " + temp);
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final CyclicItemImpl other = (CyclicItemImpl) obj;
        if (!Objects.equals(this.value, other.value)) {
            return false;
        }
        return true;
    }
}
